package cn.tedu.property_management_system.controller;

import cn.tedu.property_management_system.entity.Building;
import cn.tedu.property_management_system.entity.VO.OwnerVO;
import cn.tedu.property_management_system.entity.dto.OwnerDTO;
import cn.tedu.property_management_system.service.IOwnerService;
import cn.tedu.property_management_system.utils.JsonPage;
import cn.tedu.property_management_system.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/owner")
public class OwnerController {

    @Autowired
    IOwnerService ownerService;

    @GetMapping("/select/owner/{id}")
    public JsonResult<OwnerVO> getById(@PathVariable("id") Integer id) {
        OwnerVO ownerVO = ownerService.getById(id);
        return JsonResult.OK(ownerVO);
    }

    @PostMapping("/add/owner")
    public JsonResult<Void> addOwner(@RequestBody OwnerDTO ownerDTO) {
        log.debug(ownerDTO + "");
        ownerService.addOwner(ownerDTO);
        return JsonResult.OK();
    }

    @GetMapping("/delete/owner")
    public JsonResult<Void> deleteOwner(Integer id) {
        log.debug("+" + id);
        ownerService.deleteOwner(id);
        return JsonResult.OK();
    }

    @PostMapping("/rows/delete")
    public JsonResult<Void> deleteOwners(@RequestBody List<OwnerVO> ids) {
        log.debug("" + ids);
        ownerService.deletes(ids);
        return JsonResult.OK();
    }


    @PostMapping("/update/owner")
    public JsonResult<Void> updateOwner(@RequestBody OwnerVO ownerVO) {
        log.debug("" + ownerVO);
        ownerService.updateOwner(ownerVO);
        return JsonResult.OK();
    }

    @GetMapping("/select/owners")
    public JsonResult<List<OwnerVO>> selectListOwner() {
        log.debug("_______");
        List<OwnerVO> ownerVOS = ownerService.getOwnerVO();
        log.debug(ownerVOS + "------------------");
        return JsonResult.OK(ownerVOS);
    }


    @GetMapping("/select/owner")
    public JsonResult<List<OwnerVO>> selectOwner(String telephone, String idNumber) {
        log.debug("" + telephone + idNumber);
        List<OwnerVO> ownerVOS = ownerService.getOwnerVOByTelephonAndIdNumber(telephone, idNumber);
        return JsonResult.OK(ownerVOS);
    }

    @GetMapping("/id/tele/select")
    public JsonResult<List<OwnerVO>> select() {
        List<OwnerVO> ownerVOS = ownerService.getOwnerVO();
        return JsonResult.OK(ownerVOS);
    }

    @GetMapping("/parking/owner")
    public JsonResult<List<String>> getParkingOwner() {
        List<String> list = ownerService.getOwnerName();
        return JsonResult.OK(list);
    }

    @GetMapping("/get/page/{pageSize}/{pageIndex}")
    public JsonPage<OwnerVO> getPage(@PathVariable("pageSize") Integer pageSize, @PathVariable("pageIndex") Integer pageIndex) {
        log.debug(pageSize+"-----"+pageIndex);
        JsonPage<OwnerVO> buildingJsonPage = ownerService.pageSelect(pageSize, pageIndex);
        return buildingJsonPage;
    }


}
